/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {number}
 */
export var getDecimalValue = function (head) {
  let ans = ''
  let node = head
  while (node) {
    ans += node.val
    node = node.next
  }
  return parseInt(ans, 2)
}

/**
 * 位运算
 * @param {ListNode} head
 * @return {number}
 */
export var getDecimalValue2 = function (head) {
  let ans = 0
  let node = head
  while (node) {
    ans = (ans << 1) + node.val
    node = node.next
  }
  return ans
}
